package com.github.cyf.common.validator;

import com.github.cyf.common.validator.EnumStringValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 自定义注解校验
 * 验证某个字段的值是否为指定枚举类型的某个成员的名称
 * @author chenyifan
 * @create 2024-05-07 20:55
 */
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = EnumStringValidator.class)//标明由哪个类执行校验逻辑
public @interface EnumString {

    String message() default "";

    /**
     * @return data must in this value array
     */
    String[] value();

    /**
     * 字段类型，用于标记错误信息返回
     * @return
     */
    String type() default "";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

}
